package com.tts.dede;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

public class CascadeActivity extends Activity implements OnTouchListener {

	private Context myContext;
	private SurfaceView ourSurfaceView;
	private Debug debug = new Debug();
	private int height, width;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		myContext = getApplicationContext();
		
		DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        height = displaymetrics.heightPixels;
        width = displaymetrics.widthPixels;
		
		ourSurfaceView = new CascadeView(this);
		ourSurfaceView.setOnTouchListener(this);
		setContentView(ourSurfaceView);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		((CascadeView) ourSurfaceView).pause();
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		((CascadeView) ourSurfaceView).resume();
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		((CascadeView) ourSurfaceView).stop();
		super.onDestroy();		
	}

	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		
		if (event.getAction() == MotionEvent.ACTION_MOVE) {	
			
			debug.print("action onTouch");
			if(event.getX() >= 40 && event.getX() < width - 40)
				((CascadeView) ourSurfaceView).getMyPanier().setPosPanierX((int)event.getX()-50);
		}
		return true;
	}	
	
}
